package com.example.springboot_06_customglobalexception.common;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@ControllerAdvice(annotations = {RestController.class, Controller.class})
@ResponseBody
public class GlobalExceptionHandler {
    /*
    将自定义异常响应到网页
     */
    @ExceptionHandler(CustomException.class)
    public String exceptionHandler(CustomException ex){
        log.error(ex.getMessage());
        return ex.getMessage();
    }
}
